package com.wk1un2.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wk1un2.service.ActivityProductService;
import com.wk1un2.util.Result;

/**
 *  活动场次关联商品控制器
 * 
 * @author Administrator
 *
 */
@Controller
public class ActivityProductController {
	@Autowired
	ActivityProductService service;

	@RequestMapping("/Backstage/getAllActivityProduct")
	@ResponseBody
	public Object getAll(@RequestParam("page") int page, @RequestParam("limit") int limit,
			@RequestParam("p_id") String p_id,
			 @RequestParam("as_id") String as_id) {

		

		Integer id1=null;
		if (p_id != null && p_id!="") {
			
			id1=Integer.parseInt(p_id);
		}
		Integer id2=null;
		if (as_id != null && as_id!="") {
			
			id2=Integer.parseInt(as_id);
		}
		List<Map<String, Object>> ls = service.getAll((page - 1) * limit, limit, id1,id2);
		Result res = new Result(0, "", service.count(), ls);
		return res;
	}

//	
	@RequestMapping("/Backstage/addActivityProduct")
	@ResponseBody
	public Object add(@RequestParam Map<String, Object> map) {
		System.out.println(map.get("p_id"));
		System.out.println(map.get("as_id"));
		int i = service.add(map);
		Result res = new Result(0, "", i, i);
		return res;
	}

//	޸
	@RequestMapping("/Backstage/updateActivityProduct")
	@ResponseBody
	public Object update(@RequestParam Map<String, Object> map) {
		System.out.println(map.get("actp_id"));
		int i = service.update(map);
		Result res = new Result(0, "", i, i);
		return res;
	}

//	ɾ
	@RequestMapping("/Backstage/deleteActivityProduct")
	@ResponseBody
	public Object delete(@RequestParam("actp_id") int actp_id) {
		System.out.println(actp_id);
		int i = service.delete(actp_id);
		Result res = new Result(0, "", i, i);
		return res;
	}
}